< previous page page_47 next page >

Page 47
8. Drop down the Code window's Object box and select Form. Drop down the Code window's Event box and select Resize. You are presented with the shell of the Form_Resize event procedure. The Resize event occurs whenever the width and/or height of the form is changed, either through user actions or program code.
9. Add the following lines of code to the Form_Resize event procedure:
d6ef40187df115e88326dbc94f09ab9a.gif
lblWidth.Caption = Form1.Width
lblHeight.Caption = Form1.Height
lblLeft.Caption = Form1.Left
lblTop.Caption = Form1.Top
This code causes the current values of the form's Width, Height, Left, and Top properties to be displayed in the appropriate Label controls. Because this code is in the form's Resize event procedure, the labels will be updated whenever the size of the form changes, whether programmatically or by user action.
10. Save the form and project if you want; however, you probably don't need to bother because this is just a simple demonstration.
tip.gif
Visual Basic provides a useful tool called Auto List Members that helps with properties. When you type the name of an object followed by a dot (period), Visual Basic attempts to help you complete the dot notation by providing a pop-up list of all properties that apply to that object (along with other things that apply, such as methods and events). Just type enough characters of the desired property name to highlight it in the pop-up list. You can then press Enter or Ctrl+Enter, and the dot notation is completed for you.

d6ef40187df115e88326dbc94f09ab9a.gif d6ef40187df115e88326dbc94f09ab9a.gif
Measurements in Visual Basic
d6ef40187df115e88326dbc94f09ab9a.gif d6ef40187df115e88326dbc94f09ab9a.gif
By default, all distances are measured in twips. A twip is a device-independent unit of measure equivalent to 1/20th of a printer's point, which means that there are 1440 twips per inch. The actual physical size of a twip varies depending on screen resolution. You can specify another unit of measure for positioning and sizing objects within a container using the container's ScaleMode property. However, the screen's scale mode cannot be changed, so a form's Left, Top, Height, and Width properties are always measured in twips.
Testing the Form Resize Program
After you've completed this project, run it. Change the form's width and/or height by dragging its edges; notice how the form's labels report the modified Width and Height properties. This action illustrates how an object's properties can be changed at runtime by user action.
Next, click the Widen Form command button to cause the form's width to increase. The Width label is updated with the new property value. This example illustrates a programmatic modification of a property (even though a user initiated the action that led to the width change, the actual property change was performed by a code statement).
Finally, try moving the form (by dragging the form's title bar). By doing so, you (the user in this case) are modifying the form's Top and Left properties. One problem with this example is

 
< previous page page_47 next page >